<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Inspire - Admin and Dashboard Template</title>

    <link rel="stylesheet" type="text/css" href="/assets/css/bootstrap.min.css">

    <link rel="stylesheet" type="text/css" href="/assets/fonts/line-icons.css">

    <link rel="stylesheet" type="text/css" href="/assets/css/main.css">

    <link rel="stylesheet" type="text/css" href="/assets/css/responsive.css">
</head>
<body>
<div class="card-header border-bottom">
    <h4 class="card-title">商品添加界面</h4>
</div>
<div class="card-body">
    <div class="row">
        <div class="col-lg-10 col-md-12 col-xs-12">
            <form role="form" id="form-validation" novalidate="novalidate">
                <div class="form-group row">
                    <label class="col-sm-2 col-form-label control-label">商品名</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="cdyName">
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-sm-2 col-form-label control-label">库存</label>
                    <div class="col-sm-10">
                        <input type="number" id="stock" step="1"  min="0" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                               class="form-control" if="stock" name="stock" placeholder="" >
                    </div>

                </div>
                <div class="form-group row">
                    <label class="col-sm-2 col-form-label control-label">单价</label>
                    <div class="col-sm-10">
                        <input type="text" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" class="form-control" id="price" name="price" placeholder="">
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-sm-2 col-form-label control-label">状态</label>
                    <div class="col-sm-10">
                        <select name="state" class="form-control" id="state" >
                            <option value="">请选择</option>
                            <option value="0">库存充足</option>
                            <option value="2">库存不足</option>
                            <option value="1">无库存下架</option>
                        </select>
                    </div>
                </div>
                <input type="button" class="btn btn-common" id="baocun" value="保存"></input>
                <input type="button" class="btn btn-common" id="return" value="返回"></input>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" th:inline="javascript">

    $("#stock").blur(function () {
        var stock = Number($(this).val());
        if(stock >= 200){
            $("#state").select().val(0);
        }else if(stock > 0 && stock < 200){
            $("#state").select().val(2);
        }else{
            $("#state").select().val(1);
        }
    });



    $("#baocun").bind("click", function () {
            if(!confirm("确定保存吗")) return
            toJump("/commodity/save",$("#form-validation").serialize())

    })

    $("#return").bind("click",function () {
        toJump("/commodity/query")

    })
</script>
<script src="/assets/js/jquery-min.js"></script>
<script src="/assets/js/popper.min.js"></script>
<script src="/assets/js/bootstrap.min.js"></script>
<script src="/assets/js/jquery.app.js"></script>
<script src="/assets/js/main.js"></script>
</body>
</html>